home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / nt / emacssrc.zip / EMACSSRC.TAR / emacs-19.17 / src / vm-limit.c < prev    next >
C/C++ Source or Header  |  1993-10-24  |  4KB  |  141 lines

  1. /* Functions for memory limit warnings.
  2.    Copyright (C) 1990, 1992 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU Emacs.
  5.  
  6. GNU Emacs is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU Emacs is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU Emacs; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #ifdef emacs
  21. #include "config.h"
  22. #include "lisp.h"
  23.  
  24. #include "vm-limit_p.h"
  25. static void (*warn_function) _P_((char *str));
  26. #endif
  27.  
  28. #ifndef emacs
  29. #include <stddef.h>
  30. typedef size_t SIZE;
  31. typedef void *POINTER;
  32. #define EXCEEDS_LISP_PTR(x) 0
  33. #endif
  34.  
  35. #include "mem-limits.h"
  36.  
  37. /*
  38.   Level number of warnings already issued.
  39.   0 -- no warnings issued.
  40.   1 -- 75% warning already issued.
  41.   2 -- 85% warning already issued.
  42.   3 -- 95% warning issued; keep warning frequently.
  43. */
  44. static int warnlevel;
  45.  
  46. /* Function to call to issue a warning;
  47.    0 means don't issue them.  */
  48. #ifndef emacs
  49. static void (*warn_function) _P_((char *str));
  50. #endif
  51.  
  52. /* Get more memory space, complaining if we're near the end. */
  53.  
  54. /* static */
  55. void
  56. check_memory_limits ()
  57. {
  58.   extern POINTER (*__morecore) ();
  59.  
  60.   register POINTER cp;
  61.   unsigned long five_percent;
  62.   unsigned long data_size;
  63.  
  64.   if (lim_data == 0)
  65.     get_lim_data ();
  66.   five_percent = lim_data / 20;
  67.  
  68.   /* Find current end of memory and issue warning if getting near max */
  69.   cp = (char *) (*__morecore) (0);
  70.   data_size = (char *) cp - (char *) data_space_start;
  71.  
  72.   if (warn_function)
  73.     switch (warnlevel)
  74.       {
  75.       case 0: 
  76.     if (data_size > five_percent * 15)
  77.       {
  78.         warnlevel++;
  79.         (*warn_function) ("Warning: past 75% of memory limit");
  80.       }
  81.     break;
  82.  
  83.       case 1: 
  84.     if (data_size > five_percent * 17)
  85.       {
  86.         warnlevel++;
  87.         (*warn_function) ("Warning: past 85% of memory limit");
  88.       }
  89.     break;
  90.  
  91.       case 2: 
  92.     if (data_size > five_percent * 19)
  93.       {
  94.         warnlevel++;
  95.         (*warn_function) ("Warning: past 95% of memory limit");
  96.       }
  97.     break;
  98.  
  99.       default:
  100.     (*warn_function) ("Warning: past acceptable memory limits");
  101.     break;
  102.       }
  103.  
  104.   /* If we go down below 70% full, issue another 75% warning
  105.      when we go up again.  */
  106.   if (data_size < five_percent * 14)
  107.     warnlevel = 0;
  108.   /* If we go down below 80% full, issue another 85% warning
  109.      when we go up again.  */
  110.   else if (warnlevel > 1 && data_size < five_percent * 16)
  111.     warnlevel = 1;
  112.   /* If we go down below 90% full, issue another 95% warning
  113.      when we go up again.  */
  114.   else if (warnlevel > 2 && data_size < five_percent * 18)
  115.     warnlevel = 2;
  116.  
  117.   if (EXCEEDS_LISP_PTR (cp))
  118.     (*warn_function) ("Warning: memory in use exceeds lisp pointer size");
  119. }
  120.  
  121. /* Cause reinitialization based on job parameters;
  122.    also declare where the end of pure storage is. */
  123.  
  124. #ifndef SYSTEM_MALLOC
  125. void
  126. memory_warnings (start, warnfun)
  127.      POINTER start;
  128.      void (*warnfun) _P_((char *str));
  129. {
  130.   extern void (* __after_morecore_hook) ();     /* From gmalloc.c */
  131.  
  132.   if (start)
  133.     data_space_start = start;
  134.   else
  135.     data_space_start = start_of_data ();
  136.  
  137.   warn_function = warnfun;
  138.   __after_morecore_hook = check_memory_limits;
  139. }
  140. #endif
  141.